package sort;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Author Zhouchb
 * @Create 2021-10-2021/10/26 :16:05
 * @Description
 */
public class SelectSort {
    public static void main(String[] args) {
        Integer[] i = {3, 9, 1, 8, 5, 4, 7};
        Integer[] j = i;
        List list = new ArrayList<>();
        List list1 = new ArrayList<>();
        list.add(1);
        list.set(0, 2);
        list1 = list;
        //指向同一个内存
/*        System.out.println(list1);
        System.out.println(list);
        j[1]=6;
        System.out.println(Arrays.toString(j));
        System.out.println(Arrays.toString(i));*/
        sort(i);
    }

    public static void sort(Comparable[] arr) {
        for (int i=0;i<arr.length-1;i++){
            int min = i;
            for (int j=i+1;j< arr.length;j++){
                if (compare(arr[min],arr[j])){
                    min=j;
                }
            }
            if(min!=i){
                swap(arr,i,min);
            }
        }
        System.out.println(Arrays.toString(arr));
    }

    public static boolean compare(Comparable a, Comparable b) {
        return a.compareTo(b) > 0;
    }

    public static void swap(Comparable[] arr, int i, int j) {
        Comparable c;
        c = arr[i];
        arr[i] = arr[j];
        arr[j] = c;
    }
}
